//
//  MyListViewController.m
//  ShouYi
//
//  Created by yurui on 16/3/11.
//  Copyright © 2016年 yurui. All rights reserved.
//

#import "MyListViewController.h"

#import "MyListTableViewCell.h"
@interface MyListViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UIView *titleLine;
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation MyListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:237.0/255 green:237.0/255 blue:237.0/255 alpha:1];
    [self addTitleButton];
    [self addTableView];
}

#pragma mark --- 添加tableView ---

- (void)addTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44 + 64, kWidth, kHeight - 108) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor colorWithRed:236.0/255 green:236.0/255 blue:236.0/255 alpha:1];
    [self.tableView registerClass:[MyListTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
}


- (void)addTitleButton {
    
    NSArray *array = @[@"全部",@"待付款",@"待发货",@"待收货",@"已结束"];
    for (int i = 0; i < array.count; i++) {
        
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(kWidth / 5 * i, 64, kWidth / 5, 44);
        [button setTitle:array[i] forState:(UIControlStateNormal)];
        [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        button.backgroundColor = [UIColor whiteColor];
        [button addTarget:self action:@selector(titleClick:) forControlEvents:(UIControlEventTouchUpInside)];
        button.tag = 1000 + i;
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.view addSubview:button];
    }
    
    self.titleLine = [[UIView alloc] initWithFrame:CGRectMake(0, 64 + 42, kWidth / 5, 2)];
    self.titleLine.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.titleLine];
}

- (void)titleClick:(UIButton *)button {
    
    NSLog(@"%@",button.titleLabel.text);
    self.titleLine.frame = CGRectMake(kWidth / 5 * (button.tag - 1000), 64 + 42, kWidth / 5, 2);
    
    for (int i = 0; i < 5; i ++) {
        
        UIButton *button = (UIButton *)[self.view viewWithTag:1000 + i];
        [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    }
    
    [button setTitleColor:[UIColor redColor] forState:(UIControlStateNormal)];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor colorWithRed:236.0/255 green:236.0/255 blue:236.0/255 alpha:1];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 207.5;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
